package kr.couponplay.android.support.ad;

import kr.couponplay.android.Constants;
import kr.couponplay.android.activity.R;
import net.daum.adam.publisher.AdView;
import net.daum.adam.publisher.AdView.AnimationType;
import net.daum.adam.publisher.AdView.OnAdClickedListener;
import net.daum.adam.publisher.AdView.OnAdFailedListener;
import net.daum.adam.publisher.AdView.OnAdLoadedListener;
import net.daum.adam.publisher.impl.AdError;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class AdamAdViewPlatform implements AdPlatform {
	private AdView adamAdView;
	
    @Override
	public void onCreateAdView(Activity activity) {
    	LinearLayout adViewLayout = (LinearLayout) activity.findViewById(R.id.ad_detail_layout);
    	
//		adamAdView = (AdView) LayoutInflater.from(activity.getApplicationContext()).inflate(R.layout.ad_adam, null);
    	adamAdView = new AdView(activity);
    	
        LinearLayout.LayoutParams params = 
        		new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        adamAdView.setLayoutParams(params);
    	adViewLayout.addView(adamAdView);
    	
        adamAdView.setVisibility(View.VISIBLE);
        adamAdView.setOnAdClickedListener(new OnAdClickedListener() {
            @Override
            public void OnAdClicked() {
//                Log.i(Constants.TAG, "광고를 클릭했습니다.");
            }
        });

        adamAdView.setOnAdFailedListener(new OnAdFailedListener() {
            @Override
            public void OnAdFailed(AdError arg0, String arg1) {
                Log.i(Constants.TAG, "아담 광고 로딩 실패 : " + arg1);
            }
        });

        adamAdView.setOnAdLoadedListener(new OnAdLoadedListener() {
            @Override
            public void OnAdLoaded() {
                Log.i(Constants.TAG, "아담 광고 로딩 성공");
            }
        });

//        adamAdView.setOnAdWillLoadListener(new OnAdWillLoadListener() {
//            @Override
//            public void OnAdWillLoad(String arg1) {
//                Log.i(Constants.TAG, "광고를 불러옵니다. : " + arg1);
//            }
//        });

//        adamAdView.setOnAdClosedListener(new OnAdClosedListener() {
//            @Override
//            public void OnAdClosed() {
//                Log.i(Constants.TAG, "광고를 닫았습니다.");
//            }
//        });

        // 할당 받은 clientId 설정
        adamAdView.setClientId("525fZ0uT1401a2f4e98");
        adamAdView.setRequestInterval(12);
        adamAdView.setAnimationType(AnimationType.FLIP_HORIZONTAL);
        adamAdView.setAdCache(true);
    }

	@Override
	public void onDestroyAdView() {
		if (adamAdView != null) {
			adamAdView.removeAllViews();
			adamAdView.destroy();
			adamAdView = null;
		}
	}
}
